home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Networking / MacTCP / MacTCP Developer Tools / 802 LAP / LAP802Mdev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  3.1 KB  |  115 lines  |  [TEXT/MPS ]

  1. /* LAP802Mdev.c contains the code for mdev resource
  2.  
  3.    (c) Copyright 1990-91 by Apple Computer, Inc.  All rights reserved.
  4.    
  5. */
  6.  
  7. /*
  8.     1.2        Oct 1990    Rajesh    written for IEEE 802.3 LAP.
  9.     It contains routines to implement 'mdev' resource.
  10. */
  11.  
  12. #include <Slots.h>
  13. #include <SysEqu.h>
  14. #include <StdIO.h>
  15. #include <ToolUtils.h>
  16. #include <Memory.h>
  17. #include <Packages.h>
  18. #include <Resources.h>
  19. #include <ROMDefs.h>
  20.  
  21. #define    LOWBYTE            0x0F
  22. #define    ZERO            '0'
  23. #define    OFFSET            40
  24. #define    STR_RES_ID        -4032
  25. #define    spDrvrSWMask    0x02        /* mask off driver software field */
  26. #define spDrvrHWMask    0x01        /* mask off driver hardware field */
  27.  
  28. void addSlotInName(title, displayNo);
  29.  
  30. mdevStart()
  31. {
  32.     OSErr    rc = -1;
  33.     struct    SpBlock    sb;
  34.     char    title[255];                /* name to be displayed for LAP icon */
  35.     StringHandle    strHdl;            /* for the LAP name, 'STR ' resource */
  36.     long    prevSlotNo=0;            /* slot no. which is used for successive call */
  37.     long    currentSlotNo=0;        /* slot no. for the current card */
  38.     short    noOfCards=0;            /* used to decide whether to display a slot no */
  39.     short    displayNo;                /* the slot number to be displayed with the name */
  40.     short    nameLen;                /* length of the string to be displayed */
  41.  
  42.     prevSlotNo = GetD2();        /* start search from the next card */ /* + 1; RAJESH JUNE 4, 1991 */
  43.  
  44.     bzero((char *)&sb, sizeof(sb));
  45.     sb.spSlot = 0;    /* 1; RAJESH JUNE 4, 1991 */
  46.     sb.spCategory = catNetwork;
  47.     sb.spCType = typeEtherNet;
  48.     sb.spTBMask = spDrvrSWMask | spDrvrHWMask;
  49.                                     /* first find out how many ethernet cards are there */
  50.     while (SNextTypeSRsrc(&sb) == noErr)
  51.         noOfCards++;
  52.  
  53.     bzero((char *)title, sizeof(title));
  54.  
  55.     bzero((char *)&sb, sizeof(sb));
  56.     sb.spSlot = prevSlotNo;
  57.     sb.spCategory = catNetwork;
  58.     sb.spCType = typeEtherNet;
  59.     sb.spTBMask = spDrvrSWMask | spDrvrHWMask;
  60.     rc = SNextTypeSRsrc(&sb);
  61.     if (rc == noErr) {
  62.         currentSlotNo = sb.spSlot;
  63.         prevSlotNo = currentSlotNo;
  64.         strHdl = GetString(STR_RES_ID);
  65.         if (strHdl != nil) {
  66.             HLock(strHdl);
  67.             nameLen = *(*strHdl);
  68.             BlockMove(*strHdl,title,nameLen+1);
  69.             HUnlock(strHdl);
  70.             if (noOfCards > 1) {    /* more than 1 card, display slot number */
  71.                                     /* convert 09-0E to 1-6 range */
  72.                 displayNo = (currentSlotNo + OFFSET) & LOWBYTE;
  73.                 nameLen++;
  74.                 addSlotInName(title, displayNo, &nameLen);
  75.             }
  76.             else;
  77.                 *title = nameLen;
  78.         }
  79.         else {
  80.             rc = ResError();
  81.         }
  82.         SetA0(title);                /* Refer to MacTCP LAP Tech Note */
  83.         SetD1(currentSlotNo);        /* This is the format required by CPanel.a */
  84.         SetD2(++prevSlotNo);
  85.     }
  86.     SetD0((long) rc);                /* return status in d0 */
  87. }
  88.  
  89. void addSlotInName(title, displayNo, nameLen)
  90. char *title;
  91. short displayNo;
  92. short *nameLen;
  93. {
  94.     short    remainder;
  95.  
  96.     *(title + (*nameLen)++) = ' ';
  97.     *(title + (*nameLen)++) = '(';
  98.     if (displayNo >= 100) {
  99.         remainder = displayNo % 100;
  100.         *(title + (*nameLen)++) = (displayNo / 100) + ZERO;
  101.         *(title + (*nameLen)++) = (remainder / 10) + ZERO;
  102.         *(title + (*nameLen)++) = (remainder % 10) + ZERO;
  103.     }
  104.     else {
  105.         if (displayNo >= 10) {
  106.             *(title + (*nameLen)++) = (displayNo / 10) + ZERO;
  107.             *(title + (*nameLen)++) = (displayNo % 10) + ZERO;
  108.         }
  109.         else
  110.             *(title + (*nameLen)++) = displayNo + ZERO;
  111.     }
  112.     *(title + (*nameLen)) = ')';
  113.     *title =  *nameLen;
  114. }
  115.